<template>
  <div class="hlplan">
    <div>
      <img style="width: 100%;" src="../../assets/banner/new_banner_process_3.png"/>
    </div>
    <div class="hlplan-main">
      <van-form @submit="saveFunc">
        <!-- 患者信息 -->
        <van-cell-group inset>
          <van-field v-model="patientInfo.name" label="姓名：" placeholder="请输入姓名" readonly/>
          <van-field v-model="patientInfo.checkTypeValue" label="诊断：" placeholder="请输入诊断名称" readonly/>
        </van-cell-group>
        <!-- 治疗信息 -->
        <van-cell-group inset style="margin-top:10px;">
          <van-field v-model="baseData.treatmentMode" label="治疗方式：" placeholder="请输入治疗方式"
                     :rules="[{ required: true, message: '请输入治疗方式' ,trigger:'onSubmit'}]"
                     :readonly="userType == 1"/>
          <van-field v-model="baseData.chemotherapyRegimen" label="化疗方案：" placeholder="请输入化疗方案"
                     :rules="[{ required: true, message: '请输入化疗方案',trigger:'onSubmit' }]"
                     :readonly="userType == 1"/>
          <van-field v-model="baseData.courseNum" label="疗程数：" placeholder="请输入疗程数"
                     :rules="[{ required: true, message: '请输入疗程数',trigger:'onSubmit' }]"
                     :readonly="userType == 1"/>
          <van-field v-model="baseData.courseStartDate" label="开始时间：" placeholder="请输入开始时间"
                     :rules="[{ required: true, message: '请输入开始时间',trigger:'onSubmit'}]"
                     :readonly="userType == 1"/>
          <van-field v-model="baseData.courseCycle" label="疗程周期：" placeholder="请输入疗程周期"
                     :rules="[{ required: true, message: '请输入疗程周期',trigger:'onSubmit' }]"
                     :readonly="userType == 1"/>
          <van-field v-model="baseData.currentCourseNum" label="当前疗程数：" placeholder="请输入当前疗程数"
                     :rules="[{ required: true, message: '请输入当前疗程数',trigger:'onSubmit' }]"
                     :readonly="userType == 1"/>
          <van-field v-model="baseData.courseStatus" label="疗程状态：" placeholder="请输入疗程状态"
                     :rules="[{ required: true, message: '请输入疗程状态',trigger:'onSubmit' }]"
                     :readonly="userType == 1"/>
          <van-field v-model="baseData.planRemind" label="方案提醒：" placeholder="请输入方案提醒"
                     :rules="[{ required: true, message: '请输入方案提醒',trigger:'onSubmit' }]"
                     :readonly="userType == 1"/>
          <van-field v-model="baseData.drugInfo" label="用药情况：" placeholder="请输入用药情况"
                     :rules="[{ required: true, message: '请输入用药情况',trigger:'onSubmit' }]"
                     :readonly="userType == 1"/>
        </van-cell-group>
        <div class="hlplan-main-btn" v-if="userType == 0">
          <van-button type="primary" size="large" style="height:100%;" color="#42DDA2" :loading="isLoading"
                      native-type="submit">保存
          </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>
<script>
import {queryOneReport, saveProcessOne} from '@/api'

export default {
  data() {
    return {
      baseData: {},
      patientInfo: {
        name: "",
        checkTypeValue: ""
      },
      isLoading: false,
      userType: ''
    }
  },
  created() {
    this.patientId = this.$route.query.userid;
    this.processId = this.$route.query.processid;
    this.userType = JSON.parse(sessionStorage.getItem('userInfo')).userType;
    this.patientInfo = this.userType == 0 ? JSON.parse(sessionStorage.getItem('patientInfo')) : JSON.parse(sessionStorage.getItem('userInfo'));
    this.queryOneReportFunc();
  },
  methods: {
    // 获取单条数据
    queryOneReportFunc() {
      let data = 'processId=' + this.processId + '&userId=' + this.patientId;
      queryOneReport(data).then(res => {
        console.log('数据', res.data);
        if (res.data){
          this.baseData = res.data.baseProcessDataJson
        }
      })
    },
    // 保存化疗方案
    saveFunc() {
      let data = {
        userId: this.patientId,
        processId: this.processId,
        processData: JSON.stringify(this.baseData)
      }
      this.isLoading = true;
      saveProcessOne(data).then(res => {
        console.log('res', res)
        this.$toast('保存成功！');
        this.isLoading = false
        setTimeout(() => {
          this.$router.go(-1);
        }, 1000)
      }).catch(() => {
        this.isLoading = false
      })
    }
  }
}
</script>
<style scoped>
.hlplan {
  width: 100vw;
  height: 100vh;
  margin-bottom: 0 !important;
  background-color: #ececec;
}

.hlplan-main {
  width: auto;
  height: auto;
  padding: 10px 0px;
  background-color: #ececec;
}

.hlplan-main-btn {
  width: auto;
  height: 45px;
  padding: 0 15px;
  margin-top: 20px;
}
</style>
